home *** CD-ROM | disk | FTP | other *** search
- Path: news.csuohio.edu!usenet
- From: jabaker@grail.cba.csuohio.edu (jason)
- Newsgroups: comp.lang.c++,comp.lang.c,comp.object,comp.software-eng
- Subject: Re: Pointers are hacks in c++ (portablity hackers etc)
- Date: 26 Mar 1996 11:37:24 -0500
- Organization: Citizens for a Better Danza
- Sender: jason@jlbaker.async.csuohio.edu
- Message-ID: <vraufu7y2.fsf@jlbaker.async.csuohio.edu>
- References: <4ikb6kINN1is@mayne.ugrad.cs.ubc.ca> <DoI5Ao.AyJ@assip.csasyd.oz>
- <4j7kuf$2ur@news4.digex.net>
- NNTP-Posting-Host: jlbaker.async.csuohio.edu
- In-reply-to: ell@access4.digex.net's message of 26 Mar 1996 02:31:43 GMT
- X-Newsreader: Gnus v5.0.13
-
- In article <4j7kuf$2ur@news4.digex.net> ell@access4.digex.net (Ell) writes:
-
- > jason (jabaker@grail.cba.csuohio.edu) wrote:
- > : [ways to delete and keep track of objects elided]
- > : So, there are two questions. How was next allocated -- this can be
- > : solved by ensuring that next always comes from the heap.
-
- > 'next' should _never_ be a 'local' stack based structure.
-
- Thanks, "'next' should _never_ be a 'local' stack based structure." is
- much clearer than "ensuring that next always comes from the heap."
-
- C++ has a complicated mechanism to allow objects to live in the stack,
- heap or bss. Are you suggesting I build my own mechanism on top of it
- to ensure that objects only live on the heap? I could make a class's
- constructor protected and define a static 'newor' method to create new
- objects. But, at this point I am fighting the language and I might as
- well start overloading arithmetic operators for IO.
-
- > : And, does
- > : anything else refer to next -- this can't be solved with a reference
- > : count, we are dealing with a linked list of arbitrary length, it can
- > : only be solved by ensuring that there are no other references.
-
- > I don't see how reference counting heap based objects, which register
- > themselves in a central place, does not allow effective gc in C++.
-
- I'm not sure what you mean by "objects which register themselves in a
- central place," but is is very clear to me that you cannot maintain
- reference counts on list cells. Let's say you are using a list as a
- stack. A function f1 creates a non-empty stack, and passes it to f2.
- f2 pushes things onto it and passes it to f3. f3 pushes more things
- onto it.
-
- The list might look like this:
- refcnt == 1 refcnt == 2 refcnt == 3
- |...f3's cells...|...f2's cells...|...f1's cells
- ^f3's list ^f2's list ^f1's list
-
- Each time a new list object is created, the reference count on each
- cell accessible from it must be incremented. Imagine what happens
- when the compiler starts generating temporary list objects.
-
- I have more problems with reference counts. What happens to the
- reference count of a member object? At best it just sits there taking
- up space, and at worst (it is a public member which someone has taken
- the address of), references to the member must show up in the
- reference count of the containing object. (Automatic garbage
- collection in c++ would face the same problem.) Furthermore, objects
- on the stack or bss should have refcnt >= 1 for their entire lives,
- yet c++ does not provide a way for an object to determine how it was
- allocated.
-
- Jason
-